package gc;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;

/**
 * @author ZhengDp
 * @Date 2023/5/13 0:19
 * -Xmx20m -XX:+PrintGCDetails -verbose:gc
 */
public class WeakReference_Demo1 {

    private static final int _4MB = 4 * 1024 * 1024;
    public static void main(String[] args) {
        List<WeakReference<byte[]>> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            WeakReference<byte[]> ref = new WeakReference<>(new byte[_4MB]);
            list.add(ref);
            System.out.print("循环 " + i + " ==== > ");
            for(WeakReference<byte[]> w : list) {
                System.out.print(w.get() + " ");
            }
            System.out.println();
        }
        System.out.println("循环结束：" + list.size());
    }
}
